package concurrent.mysynchronized;

/**
 * @package concurrent.mysynchronized
 * @Class SynchronizedObjectCodeBlock2
 * @Description TODO
 * @Author zhangxinhua
 * @Date 20-1-9 上午11:27
 */
public class SynchronizedObjectMethod3 implements Runnable {
    static SynchronizedObjectMethod3 synchronizedObjectCodeBlock2 = new SynchronizedObjectMethod3();
    @Override
    public void run() {
        method();
    }

    public synchronized void method() {
        System.out.println("我是对象锁的方法修饰符形式，我叫"+Thread.currentThread().getName());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"执行完毕");
    }
    public static void main(String[] args) {
        Thread t1 = new Thread(synchronizedObjectCodeBlock2);
        Thread t2 = new Thread(synchronizedObjectCodeBlock2);
        t1.start();
        t2.start();
        while (t1.isAlive() || t2.isAlive()) {

        }
        System.out.println("finished:");
    }
}
